package com.landcode.land.service.hi.controller;

import com.landcode.land.service.hi.model.Test;
import com.landcode.land.service.hi.model.User;
import com.landcode.land.service.hi.service.UserService;
import com.landcode.land.service.hi.service.impl.HiServ;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping(value = "/hi")
public class HiController {

    @Autowired
    private HiServ hiServ;

    @Autowired
    private UserService userService;

    @Value("${server.port}")
    private String port;

    @GetMapping(value = "/list")
    public List<User> getUsers() {
        return userService.getUserList();
    }

    @GetMapping(value = "/{id}")
    public User getUserName(@PathVariable long id) {
        return userService.getUserName(id);
    }

    @GetMapping(value = "/test/{name}")
    public List<Test> getUserTest(@PathVariable String name) {
        return userService.getUserTest(name);
    }

    @PostMapping(value = "/addUser")
    public int addUserName(@RequestBody User user) {
        return userService.insertUser(user);
    }

    @RequestMapping(value = "/hi")
    public String hi() {
        return "hi " + port;
    }

    @RequestMapping(value = "/hiServ")
    public String hiServ() {
        return hiServ.doHi();
    }

    @RequestMapping(value = "/err")
    public int err() {
        log.error("i am test");
        throw new RuntimeException();
    }
}
